package br.ufmg.dcc.vod.remoteworkers.functional.simplesystem;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import br.ufmg.dcc.vod.remoteworkers.async.AsyncCommandProcessor;
import br.ufmg.dcc.vod.remoteworkers.async.CommandInterested;
import br.ufmg.dcc.vod.remoteworkers.async.SimpleCommandRequest;
import br.ufmg.dcc.vod.remoteworkers.registry.ServiceRegistry;

public class MainClient {

	public static void main(String[] args) throws MalformedURLException, RemoteException, AlreadyBoundException, NotBoundException {

		StringCommandInterested sci = new StringCommandInterested(7878);
		ServiceRegistry<CommandInterested<?, ?>> cr = new ServiceRegistry<CommandInterested<?, ?>>(7878);
		cr.bindProcessor("Client", sci);
		
		sci.start();
		
		AsyncCommandProcessor p = (AsyncCommandProcessor) Naming.lookup("rmi://localhost:7888/Queue");
		
		int i = 0;
		while (true) {
			StringCommand sc = new StringCommand(i++ + "");
			p.process(new SimpleCommandRequest<String, String>(sc, sci, ""));
		}
	}
}
